package factories;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Random;

import org.tbjd.client.beans.Task;

/**
 * 
 * @author Michael Martin
 * @author Antonio Carrozzini
 * @version 1.0
 * 
 */
public class TaskFactory {

	static private Random r = new Random();
	static private DateFormat df = DateFormat.getInstance();

	static {
		df = new SimpleDateFormat("dd.MM.yyyy");
	}

	static public Task getInstance() {
		Task task = new Task();

		task.setId(r.nextInt(100));
		task.setName("Foo Task");
		task.setLevel(r.nextInt(20));
		task.setType(Task.TASK);
		try {
			task.setBeginDate(df.parse("01.06.2009"));
			task.setEndDate(df.parse("02.06.2009"));

		} catch (ParseException e) {
			e.printStackTrace();
			
		}
		task.setDuration(24);
		task.setEffort(24);
		task.setProgress(1 + r.nextInt(100));

		return task;
	}

	static public float getDuration(Task task) {
		return (task.getEndDate().getTime() - task.getBeginDate().getTime()) / 3600000;
	}

}
